package com.haidechizi.fastadmin.modules.sys.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.haidechizi.fastadmin.common.page.PageDto;
import com.haidechizi.fastadmin.common.utils.PageInfo;
import com.haidechizi.fastadmin.modules.sys.dao.SysLogDao;
import com.haidechizi.fastadmin.modules.sys.entity.SysLog;
import com.haidechizi.fastadmin.modules.sys.service.SysLogService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;


@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogDao, SysLog> implements SysLogService {

    @Override
    public PageInfo queryPage(PageDto pageDto, SysLog sysLog) {
        Wrapper<SysLog> wrapper;
        String userName = sysLog.getUsername();
        Page<SysLog> page = this.selectPage(
                pageDto.cover2Page(),
                wrapper = new EntityWrapper<SysLog>().like(StringUtils.isNotBlank(userName), "username", userName)
        );
        int count = super.selectCount(wrapper);
        page.setTotal(count);
        return new PageInfo(page);
    }
}
